/**
 * Created by zl on 2017/4/7.
 */
var charityApp = angular.module('charityApp', [ 'ui.router','home.controller','donation.controller','commonPageModule','informationModule','userModule','paynotifyModule','weixinpayModule']);
charityApp.config(function ($stateProvider, $urlRouterProvider){
    $urlRouterProvider.otherwise('/');
    $stateProvider.state('home', {
        url: '/',
        templateUrl: 'web/pages/home/home.html',
        controller:'homeController'
    });
    $stateProvider.state('commonPages', {
        url: '/:menuKeyCode/:subMenuId',
        templateUrl: 'web/pages/contentpage/content.html',
        controller: 'commonPageCtrl'
    });

    $stateProvider.state('commonSinglePage', {
        url: '/:menuKeyCode/:subMenuId/:contentId',
        templateUrl: 'web/pages/contentpage/content.html',
        controller: 'commonPageCtrl'
    });

    $stateProvider.state('information', {
        url: '/information',
        controller: 'informationCtrl',
        templateUrl: 'web/pages/information/information.html'
    });

    $stateProvider.state('register', {
        url: '/register',
        templateUrl: 'web/pages/user/register.html',
        controller: 'userRegisterController'
    });
    $stateProvider.state('findPassword', {
        url: '/findPassword',
        templateUrl: 'web/pages/user/findpassword.html',
        controller: 'resetPasswordByEmailCtrl'
    });
    $stateProvider.state('setNewPasswordByEmail', {
        url: '/newPassword',
        templateUrl: 'web/pages/user/resetpassword.html',
        controller: 'setNewPasswordByEmailCtrl'
    })

    $stateProvider.state('weixinpay', {
            url: '/weixinpay',
            templateUrl: 'web/pages/weixinpay/pay-qrcode.html',
            controller: 'weixinpayController'
        });
    $stateProvider.state('paynotify', {
        url: '/paynotify',
        templateUrl: 'web/pages/paynotify/pay-notify.html',
        controller: 'paynotifyController'
    });

}).run(['$http',function($http){
    window.LOCAL_STORE.context.open(GLOBAL_SESSION);
    window.LOCAL_STORE.context.session = window.LOCAL_STORE.context.session || {};
    $http({
        method: 'GET',
        url: '/dataAnalysis/latestDonations'
    }).then(function (result) {
        if(result.data && result.data.code === 0){
            window.LOCAL_STORE.context.session.donationList = result.data.data;
            LOCAL_STORE.context.rme(GLOBAL_SESSION);
        }
        // console.log(window.LOCAL_STORE.context.session.donationList);
    });

    $http({
        method: 'GET',
        url: '/globalMenus'
    }).then(function (result) {
        if(result.data && result.data.code === 0){
            window.LOCAL_STORE.context.session.globalMenus = result.data.data;
            LOCAL_STORE.context.rme(GLOBAL_SESSION);
        }
        // console.log(window.LOCAL_STORE.context.session.globalMenus);
    });
}]);